define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'user/withdraw/index' + location.search,
                    add_url: '',
                    edit_url: '',
                    del_url: '',
                    multi_url: 'user/withdraw/multi',
                    import_url: 'user/withdraw/import',
                    table: 'user_withdraw',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                fixedColumns: true,
                fixedRightNumber: 1,
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'user_id', title: __('User_id')},
                        {field: 'user.nickname', title: __('User.nickname'), operate: 'LIKE'},
                        {field: 'user.mobile', title: __('注册手机号'), operate: 'LIKE'},
                        {field: 'user.ali_account', title: __('支付宝收款号'), operate: 'LIKE'},
                        {field: 'user.wx_account', title: __('微信收款号'), operate: 'LIKE'},
                        {field: 'log_id', title: __('Log_id')},
                        {field: 'log_rn_id', title: __('Log_rn_id')},
                        {field: 'price', title: __('Price'), operate: 'BETWEEN'},
                        {field: 'num', title: '金币/钻石'},
                        {
                            field: 'status', title: __('Status'),
                            searchList: {'0': "申请中", "1": "已打款", "2": "已拒绝"},
                            formatter: Table.api.formatter.flag
                        },
                        {
                            field: 'type', title: __('Type'),
                            searchList: {"1": "金币", "2": "钻石"},
                            formatter: Table.api.formatter.flag
                        },
                        {
                            field: 'with_method', title: __('到账方式'),
                            searchList: {"1": "支付宝", "2": "微信", "3": "手动打款"},
                            formatter: Table.api.formatter.flag
                        },
                        {
                            field: 'desc',
                            title: __('Desc'),
                            operate: 'LIKE',
                            table: table,
                            class: 'autocontent',
                            formatter: Table.api.formatter.content
                        },
                        {
                            field: 'createtime',
                            title: __('Createtime'),
                            operate: 'RANGE',
                            addclass: 'datetimerange',
                            autocomplete: false,
                            formatter: Table.api.formatter.datetime
                        },
                        {
                            field: 'updatetime',
                            title: __('Updatetime'),
                            operate: 'RANGE',
                            addclass: 'datetimerange',
                            autocomplete: false,
                            formatter: Table.api.formatter.datetime
                        },
                        {
                            field: 'operate',
                            title: __('Operate'),
                            table: table,
                            events: Table.api.events.operate,
                            formatter: Table.api.formatter.operate,
                            buttons: [
                                {
                                    name: 'tongguo',
                                    text: __('通过'),
                                    title: __('通过'),
                                    classname: 'btn btn-xs btn-primary btn-ajax',
                                    confirm: '确认提现金额打款?',
                                    icon: 'fa fa-check',
                                    url: 'user/withdraw/tongguo/id/{ids}',
                                    visible: function (row) {
                                        //返回true时按钮显示,返回false隐藏
                                        if (row.status == 0) {
                                            return true;
                                        }
                                        return false;
                                    },
                                    success: function (data, ret) {
                                        layer.alert(ret.msg);
                                        table.bootstrapTable('refresh', {});
                                        return false;
                                    },
                                },
                                {
                                    name: 'jujue',
                                    text: __('拒绝'),
                                    title: __('拒绝'),
                                    confirm: '确认拒绝该申请?',
                                    classname: 'btn btn-xs btn-danger btn-dialog',
                                    icon: 'fa fa-close',
                                    url: 'user/withdraw/jujue/id/{ids}',
                                    success: function () {
                                    },
                                    visible: function (row) {
                                        //返回true时按钮显示,返回false隐藏
                                        if (row.status == 0) {
                                            return true;
                                        }
                                        return false;
                                    }
                                },
                                {
                                    name: 'manual',
                                    text: __('手动打款'),
                                    title: __('手动打款'),
                                    confirm: '确认该款项已打款完毕?',
                                    classname: 'btn btn-xs btn-success btn-ajax',
                                    icon: 'fa fa-check',
                                    url: 'user/withdraw/manual/id/{ids}',
                                    success: function () {
                                    },
                                    visible: function (row) {
                                        //返回true时按钮显示,返回false隐藏
                                        if (row.status == 0) {
                                            return true;
                                        }
                                        return false;
                                    }
                                }
                            ]
                        }
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        jujue: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
